package com.cube.reactive.guide.reactive;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Scheduler;
import reactor.core.scheduler.Schedulers;

/**
 * @author litb
 * @since 2024/6/11 20:11
 */
public class ThreadDemo {

    public static void main(String[] args) throws InterruptedException {
        //final Mono<String> mono = Mono.just("hello ");
        //System.out.println(Thread.currentThread().getName());
        //Thread t = new Thread(() -> mono
        //        .map(msg -> msg + "thread ")
        //        .subscribe(v ->
        //                System.out.println(v + Thread.currentThread().getName())
        //        )
        //);
        //t.start();
        //t.join();


        Scheduler s = Schedulers.newParallel("parallel-scheduler", 4);

        final Flux<String> flux = Flux
                .range(1, 100)
                .map(i -> 10 + i)
                .publishOn(s)
                .map(i -> "value " + i);

        //new Thread(() -> flux.subscribe(v -> {
        //    System.out.println(Thread.currentThread().getName() + " " + v);
        //})).start();

        flux.subscribe(v -> {
            System.out.println(Thread.currentThread().getName() + " " + v);
        });

        Thread.sleep(5000);
    }
}
